package com.lz.frame.config.security;

import java.util.*;
import java.util.stream.*;
import com.lz.frame.domain.VO.UserVO;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;

@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class MyUserDetails02 implements UserDetails, Serializable {

    private UserVO userVO;


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if (userVO.getRoles() != null) {
            List<SimpleGrantedAuthority> collect = userVO.getRoles().stream()
                    .map(role -> new SimpleGrantedAuthority(role.getRoleName()))
                    .collect(Collectors.toList());
            System.out.println("roleList" + collect);
            return collect;
        }
        return Collections.emptyList();
    }

    @Override
    public String getPassword() {
        return userVO.getUser().getPassword();
    }

    @Override
    public String getUsername() {
        return userVO.getUser().getUsername();
    }

    //账号是否未过期 默认永不过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    //账号是否未锁定 默认未锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    //密码是否未过期   默认永不过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    //账号是否可用
    @Override
    public boolean isEnabled() {
        return true;
    }
}